#include <CD74HC4051.h>

ti::CD74HC4051::CD74HC4051(PinName pin_en,PinName pin_s0,PinName pin_s1,PinName pin_s2):
    _en(pin_en),
    _s0(pin_s0),
    _s1(pin_s1),
    _s2(pin_s2)
{
    _s0 = 0;
    _s1 = 0;
    _s2 = 0;
    _en = 1;
}
ti::CD74HC4051::~CD74HC4051()
{
    
}
void ti::CD74HC4051::enable(bool en)
{
    _en = en?0:1;
}
void ti::CD74HC4051::select_channel(ChannelName name)
{
    switch ((name))
    {
    case ChannelName::A0:
        {
            _s0 = 0;
            _s1 = 0;
            _s2 = 0;
        }
        break;
    case ChannelName::A1:
        {
            _s0 = 1;
            _s1 = 0;
            _s2 = 0;
        }
        break;
    case ChannelName::A2:
        {
            _s0 = 0;
            _s1 = 1;
            _s2 = 0;
        }
        break;
    case ChannelName::A3:
        {
            _s0 = 1;
            _s1 = 1;
            _s2 = 0;
        }
        break;
    case ChannelName::A4:
        {
            _s0 = 0;
            _s1 = 0;
            _s2 = 1;
        }
        break;
    case ChannelName::A5:
        {
            _s0 = 1;
            _s1 = 0;
            _s2 = 1;
        }
        break;
    case ChannelName::A6:
        {
            _s0 = 0;
            _s1 = 1;
            _s2 = 1;
        }
        break;
    case ChannelName::A7:
        {
            _s0 = 1;
            _s1 = 1;
            _s2 = 1;
        }
        break;
    default:
        break;
    }
}